package com.th.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.th.bean.Setmeal;
import com.th.common.CustomerException;
import com.th.mapper.SetmealMapper;
import com.th.service.SetmealDishService;
import com.th.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {
    @Autowired
    private SetmealDishService setmealDishService;
    @Override
    @Transactional
    public void removeWithDish(List<Long> ids) {
        LambdaQueryWrapper<Setmeal> slw = new LambdaQueryWrapper<>();
        slw.in(Setmeal::getId,ids);
        slw.eq(Setmeal::getStatus,0);

        int count = this.count(slw);

        if(count>0){
            this.removeByIds(ids);
        }else {
            throw  new CustomerException("选中菜品有正在销售的");
        }

        setmealDishService.removeByIds(ids);

    }
}
